package proguardcreater;

import java.util.ArrayList;
import java.util.List;

/*
Android中如何开启变态混淆防止被反编译
https://blog.csdn.net/XXOOYC/article/details/80847681


Unicode字符
https://blog.csdn.net/dadan1314/article/details/87855037

Unicode 字符表
https://unicode-table.com/cn/blocks/


http://www.unicode.org/charts/
 */
public class ProgardEx {
    private static final String outTxt = "CasinoMegaFish_package.txt";
    public static void main(String[] args) {
        try {
            genWordsTxt();
        } catch (Exception e) {
            e.printStackTrace();
        }

    }

    private static void genWordsTxt() {
        List<String> list = new ArrayList<>();
//        list.addAll(getStringList(0xFE70, 0xFFFF));//各种符号 android混淆不通过
//        list.addAll(getStringList(0x2200,  0x22FF));//数学运算符  范围: 2200—22FF 字符总数: 256  android混淆不通过

        // android 混淆可行
        list.addAll(getStringList(0x2100,  0x214F));//FlamaCredito_guard4.txt  字母式符号  范围: 2100—214F 字符总数: 80  https://unicode-table.com/cn/blocks/letterlike-symbols/


        int wordsLength = 6;
        writeToText(list, wordsLength);
    }

    private static List<String> getStringList(int start, int end) {
        ArrayList<String> list = new ArrayList<>();
        for (int i = start; i < end; i++) {
            String s = String.valueOf((char) i);
            list.add(s);
        }
        return list;
    }

    private static void writeToText(List<String> list, int wordsLength) {

        try {
//            int count = list.size();
            int count = 30000;
//            PrintWriter writer = new PrintWriter(new File(outTxt));
            for (int i = 0; i < count; i++) {

                StringBuffer sb = new StringBuffer();
                for (int j = 0; j < wordsLength; j++) {
                    sb.append(getRandomItem(list));
                }
//                writer.println(sb.toString());
                FileUtils.appendFile(outTxt, sb.toString());
                System.out.println("write:" + sb);
            }
//            writer.close();
            System.out.println("write Done,Cout:" + count);
        } catch (Exception e) {
            e.printStackTrace();
            System.out.println("Fail!");
        }
    }

    private static String getRandomItem(List<String> list) {
        long max = list.size() - 1;
        long min = 0;
        double valueD = (Math.random() * (max - min) + min);//5-10s
        int value = (int) valueD;
        return list.get(value);
    }

}
